package com.shoulei.designpattern.filterPattern;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName:CriteriaPatternDemo
 * @Descrition:
 * @Author:shoulei
 * @Date:2019/4/14 10:35
 * @Verson:
 */
public class CriteriaPatternDemo {
    public static void main(String[] args) {
        List<Person> persons = new ArrayList<Person>();
        Person p1 = new Person("zhangsan","male","single");
        Person p2 = new Person("lisi","male","single");
        Person p3 = new Person("wangermazi","female","married");
        Person p4 = new Person("zhou","female","single");
        persons.add(p1);
        persons.add(p2);
        persons.add(p3);
        persons.add(p4);
        CriteriaMale male = new CriteriaMale();
        List<Person> males = male.meetCriteria(persons);
        System.out.println("males:");
        for(Person person : males){
            System.out.println(person.toString());
        }
        CriteriaFemale female = new CriteriaFemale();
        List<Person> females = female.meetCriteria(persons);
        System.out.println("females:");
        for (Person person : females){
            System.out.println(person.toString());
        }

        CriteriaSingle single = new CriteriaSingle();
        Criteria maleSingle = new AndCriteria(male,single);
        System.out.println("male and single:");
        for(Person person:maleSingle.meetCriteria(persons)){
            System.out.println(person.toString());
        }

        Criteria maleOrSimple = new OrCriteria(male, single);
        System.out.println("male or single:");
        for(Person person:maleOrSimple.meetCriteria(persons)){
            System.out.println(person.toString());
        }
    }
}
